<?php

namespace App\Modules\LuckDraw\Award;

use App\Http\Model\Gift;
use App\Http\Model\GiftBag;

class GiftAward extends BaseAward implements AwardInterface {

    public $type = 1;//类型 0未中奖 1:礼物 2:商品 3:金豆礼物/珍珠礼物

    public function __construct(
        int $luckId,
        int $userId,
        int $awardId,
        int $timeLimit,
        int $price
    ){
        $this->luckId = $luckId;
        $this->userId = $userId;
        $this->awardId = $awardId;
        $this->timeLimit = $timeLimit;
        $this->price = $price;
    }
    public function save(): bool {
       // TODO: Implement save() method.
       return (new GiftBag())->inc($this->userId, 0, $this->awardId,  $this->num, $this->luckId);
    }
    public function detail() {
        $gift = (new Gift())->get_gift($this->awardId);
        $this->name = $gift['name'];
        $this->image = $gift['image'];
        $this->animateResource = $gift['animate_resource']??'';
//        $this->price = $gift['price'] ?? 0;
        $this->_getAperture();
    }

    private function _getAperture(){
        if ($this->price >= 0 and $this->price < 100000) {
            $this->aperture = 1;
        } elseif ($this->price >= 100000 and $this->price < 300000) {
            $this->aperture = 2;
        } elseif ($this->price >= 300000) {
            $this->aperture = 3;
        } else {
            $this->aperture = 0;
        }
    }

}